import com.Lyy.Mapper.StudentMapper;
import com.Lyy.cla.MBStudent;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import com.Lyy.uity.MBgetSession;

import java.io.IOException;
import java.util.List;

public class student {
    @Test
    public void select() throws IOException {
        MBStudent Student1 = new MBStudent();
        Student1.setId(1);
        Student1.setName("test1");

        SqlSession sqlSession = MBgetSession.getsqlSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);
        List<MBStudent> mbStudents = mapper.MBSelectStudent(Student1);
        System.out.println(mbStudents);

    }

    @Test
    public void update() throws IOException {
        MBStudent MBStudentUpd = new MBStudent(6, "test7");

        SqlSession sqlSession = MBgetSession.getsqlSession();
        int num = sqlSession.getMapper(StudentMapper.class).MBUpdStudent(MBStudentUpd);
        sqlSession.commit();
        if (num > 0) {
            System.out.println("成功修改" + num + "条信息");
        }else{
            System.out.println("未作更改");
        }
    }

    @Test
    public void dele() throws IOException {
        MBStudent Student1 = new MBStudent();
        Student1.setId(6);
//        Student1.setName("test6");

        SqlSession sqlSession = MBgetSession.getsqlSession();
        int num = sqlSession.getMapper(StudentMapper.class).MBDelStudent(Student1);

        sqlSession.commit();
        if (num > 0) {
            System.out.println("成功删除" + num + "条信息");
        }else{
            System.out.println("未作更改");
        }

    }

    @Test
    public void add() throws IOException {
        MBStudent MBStudentAdd = new MBStudent(6, "test6");
        SqlSession sqlSession = MBgetSession.getsqlSession();

        int num = sqlSession.getMapper(StudentMapper.class).MBAddStudent(MBStudentAdd);

        sqlSession.commit();

        if (num > 0) {
            System.out.println("成功添加" + num + "条信息");
        }else{
            System.out.println("未作更改");
        }
    }

}
